package com.yegs.jltqc.controller;

import com.yegs.jltqc.TO.NamePageQuery;
import com.yegs.jltqc.VO.BaseMenu;
import com.yegs.jltqc.common.StoreException;
import com.yegs.jltqc.config.Msg;
import com.yegs.jltqc.service.BaseMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/baseMenu")
public class BaseMenuController {

    @Autowired
    private BaseMenuService baseMenuService;

    @PostMapping("/save")
    public Msg save(@RequestBody BaseMenu baseMenu){
        try{
            baseMenuService.save(baseMenu);
            return Msg.success();
        }catch (StoreException e){
            return Msg.error(e.getMessage());
        }
    }
    @GetMapping("/list")
    public Msg list(){
        return Msg.success("list",baseMenuService.list());
    }


    @GetMapping("/get")
    public Msg get(@RequestParam Long id){
        return Msg.success("data",baseMenuService.get(id));
    }

    @GetMapping("/del")
    public Msg del(@RequestParam Long id){
        baseMenuService.del(id);
        return Msg.success();
    }


    @PostMapping("/query")
    public Msg query(@RequestBody NamePageQuery query){
        return Msg.success("page",baseMenuService.query(query));
    }



}
